<?php
class Database {
    static function factory( $driver_name, $host = null, $user = null, $pass = null, $database = null, $charset = null ) {
        if( $host === null || $user === null || $pass === null || $database === null ) {
            $host = Config::get( 'host', 'db_config');
            $user = Config::get( 'user', 'db_config');
            $pass = Config::get( 'pass', 'db_config');
            $database = Config::get( 'database', 'db_config');
            $charset = Config::get( 'charset', 'db_config' );
        }
        $db = new PDO( 'mysql:dbname=' . $database . ';host=' . $host . ';charset=' . $charset, $user, $pass );
        $db -> setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
        $db -> query( 'SET NAMES ' . $charset );
        return $db;
    }
}